package com.demo.websocket;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * 解决找不到seesion的问题
 */
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        Object object = request.getHttpSession();
        if (object == null) {
            object = new Object();
        }
        sec.getUserProperties().put(HttpSession.class.getName(), object);
    }

}
